<%--                                                                       --%>
<%-- Copyright (c) 2001-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean" %>

<script language="JavaScript">

function confirmDelete(phaseNum) {
  if ( confirm('<bean:message key="cs.confirm.delete.phase"/>') ){
    return true;
  } else {
    return false;
  }
}        


// the second parameter is true if it is addCase, false otherwise
function validateFields(theForm, addCase) {
  if (validateWizardPhaseAddForm(theForm) == false) {
    return false;
  }
  
  //
  // Check duplicate phase name. 
  //
  
  var i;
  
  // check the case where no phase exists
  if (theForm.existingPhaseName == null ) {
    return true;
  }

  // check the case where only one phase exists
  var phaseLen = theForm.existingPhaseName.length;
  
  
  if (phaseLen == null || phaseLen == undefined) {
  
    
    if (addCase) {
      if (theForm.phaseName.value == theForm.existingPhaseName.value) {
        alert('<bean:message key="cs.error.phase.name.exist"/>');
        return false;
      }
    }
    return true;
  }
   
  // check there is more than one existing phase case
  for ( i = 0; i < phaseLen; i++ ) {
    
    var onePhaseName = theForm.existingPhaseName[i].value;
    var duplicate = false;
    
    if ( theForm.phaseName.value == onePhaseName ) {
    
      if(addCase) {
        duplicate = true;
      }
      
      else {
        if (theForm.phaseToProcess.value != i) {
          duplicate = true;
        }
      }  
      
      if (duplicate) {
        alert('<bean:message key="cs.error.phase.name.exist"/>');
        return false;
      }
    } // end found duplicate case
  } // end for loop
  
  return true;
}                                 

function clickAdd(theForm) {
  if (validateFields(theForm, true)) {
    theForm.submit();
  } else {
    return false;
  }
}

function clickUpdate(theForm) {
  if (validateFields(theForm, false)) {
    theForm.action = '<c:url value="/cs/microsite/phaseSave.do"/>';
    theForm.submit();
  } else {
    return false;
  }
}

function confirmCancel(theForm) {
  if ( confirm('<bean:message key="cs.confirm.cancel.microsite"/>') ){
    theForm.action = '<c:url value="/cs/microsite/cancelWizard.do"/>';
    theForm.submit();
  } else {
    return false;
  }
}

function clickBack(theForm) {
  theForm.action = '<c:url value="/cs/microsite/msNewDetails.do"/>';
  theForm.submit();
}

function clickNext(theForm) {
  theForm.action = '<c:url value="/cs/microsite/participantList.do"/>';
  theForm.submit();
}


</script>

<!-- Zone 5 starts here.  -->

<html:javascript formName="/cs/microsite/phaseAdd" method="validateWizardPhaseAddForm"/>

<html:form action="/cs/microsite/phaseAdd.do">

<html:hidden name="msNewForm" property="templateId"/>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" 
       summary="add phase in microsite creation wizard">
  <tr>
    <td valign="top">
    
    <div class="pageTitle">
      <bean:message key="ep.wizard.pageTitle" 
                    arg0="${msNewForm.map.currentStep}"/><bean:message key="cs.phases"/>
    </div>
      
    <div class="errorMessage">
      <html:errors/>
    </div>
    <!-- start title bar here -->
    <div class="pageSubtitle">
      <span class="left">
        <c:if test="${msNewForm.map.isNew}">
          <bean:message key="cs.phase.add"/>
        </c:if>
        <c:if test="${!msNewForm.map.isNew}">
          <bean:message key="cs.phase.edit"/>
        </c:if>
      </span>
    </div> 
    <!--end title bar here --> 
    
    <div class="blockWrap">
    
    <!-- start Page Instructions -->
    <div class="pageInstructions">
      <bean:message key="cs.phase.note"/>
    </div>
    <!-- End Page Instructions -->
        
    <!--start main content area here -->
    <table class="labelForm" width="100%" border="0" cellspacing="0" 
           cellpadding="0" summary="Phase Information">
             
      <tr> 
        <td nowrap width="20%" class="label"><bean:message key="cs.name"/> *: </td>
        <td width="80%" nowrap class="labelField"> 
          <html:text property="phaseName" size="31" maxlength="80"/>
        </td>
      </tr>
      <tr> 
        <td nowrap width="20%" class="label"> 
          <bean:message key="cs.description"/>: 
        </td>
        <td width="80%" nowrap class="labelField"> 
           <html:textarea property="phaseDescription" cols="30" rows="4"/>
        </td>
      </tr>
      <tr> 
        <td nowrap width="20%" class="label"><bean:message key="cs.goal"/>:</td>
        <td width="80%" nowrap class="labelField"> 
          <html:textarea property="phaseGoal" cols="45" rows="4"/> 
        </td>
      </tr>
      
      <!-- show list of phases with radio buttons, so that user can 
           specify the position of the new phase. -->
      <tr> 
        <td nowrap width="20%" class="label">
          <bean:message key="cs.phase.new.setphase.before"/>:
        </td>
        <td width="80%" nowrap class="labelField">
          <c:forEach var="aPhase" items="${msNewForm.map.phaseList}" 
                     varStatus = "position" >
                     
            <html:radio property="positionBefore" value="${position.count-1}" />
            <c:out value="${aPhase.map.phaseName}"/><br>
          </c:forEach>
          <html:radio property="positionBefore" value="-9999" />
          <bean:message key="cs.phase.new.addtolast" /><br>
        </td>
      </tr>
      
    </table>
    <!--start cancel, back, reset bar area here -->
      
    <div class="pageButtonWrap" align="right">
      <html:reset styleClass="pageButton" property="resetBtn"  titleKey="button.reset">
          <bean:message key="button.reset"/>
      </html:reset>  
      
      <input type="hidden" name="addCase" value="${msNewForm.map.isNew}"/>
      <c:if test="${msNewForm.map.isNew}">
      <html:button styleClass="pageButton" property="addToList" 
             titleKey="button.addToList" onclick="return clickAdd(this.form)">
        <bean:message key="button.addToList"/>
      </html:button>
      </c:if>
      <c:if test="${!msNewForm.map.isNew}">
        <input type="hidden" name="phaseToProcess" value='<c:out value="${msNewForm.map.phaseToProcess}"/>'/>
        <html:button styleClass="pageButton" property="save" 
             titleKey="button.save" onclick="return clickUpdate(this.form)">
        <bean:message key="button.save"/>
      </html:button>      
      </c:if>
                    
    </div>   
    
    </div>  
   

    <!--end page title area here -->
    
    <div class="pageSubtitle">
      <span class="left">
        <bean:message key="cs.phase.list"/>
      </span>
    </div> 

    <!--end title bar here -->
     
    <div class="blockWrap">
     
    <%-- include the participant file list file --%>
    
    <%@ include file="/cs/microsite/wizard/msPhaseEditListBody.jsp" %>
    
             
  
 
    <!--start cancel, back, next bar area here -->
    <div class="pageButtonWrap" align="right">
      <html:button styleClass="pageButton" property="cancelBtn" titleKey="button.cancel" 
                   onclick='return confirmCancel(this.form)'>
        <bean:message key="button.cancel"/>
      </html:button>
      
                   
      <html:button styleClass="pageButton" property="backBtn" titleKey="button.back" onclick="clickBack(this.form)">
        <bean:message key="button.back"/>
      </html:button>
      
      <c:choose>
        <c:when test="${not empty msNewForm.map.phaseList}">
          <html:button styleClass="pageButton" property="nextBtn" 
          						 titleKey="button.next" onclick="return clickNext(this.form)">
              <bean:message key="button.next"/>
          </html:button>
        </c:when>
        <c:otherwise>
          <html:button styleClass="pageButton" property="nextBtn" 
                       titleKey="button.next" disabled="true" 
                       onclick="return clickNext(this.form)">
            <bean:message key="button.next"/> 
          </html:button>
        </c:otherwise>
      </c:choose>
    </div>  
    
    </div>

           
    </td>
  </tr>
</table>
</html:form>
<!--end zone 5 content here --> 

